package collections;
import java.util.*;

class PQ {
	static class PQsort implements Comparator<Integer> {	//invert sort
		public int compare(Integer one, Integer two) {
			return two - one;
		} 
	}
	public static void main(String... args) {
		int[] ia = {1,5,3,7,6,9,8};	//unordered data
		PriorityQueue<Integer> pq1 = new PriorityQueue<Integer>();	//use natural order
		
		for(int x : ia)	//load queue
			pq1.offer(x);
		for(int x : ia)	//review queue
			System.out.print(pq1.poll() + " ");
		System.out.println(" ");
		
		PQsort pqs = new PQsort();	//get a Comparator
		PriorityQueue<Integer> pq2 = new PriorityQueue<Integer>(10,pqs);	//use Comparator
		
		for(int x : ia)	//load queue
			pq2.offer(x);
		System.out.println("size " + pq2.size());
		System.out.println("peek " + pq2.peek());
		System.out.println("size " + pq2.size());
		System.out.println("poll " + pq2.poll());
		System.out.println("size " + pq2.size());
		
		for(int x : ia)	//review queue
			System.out.print(pq2.poll() + " ");
		
		System.out.println();
		
		//natural ordering
		String[] sa = {">ff<", "> f<", ">f <", ">FF<"};
		PriorityQueue<String> pq3 = new PriorityQueue<String>();
		for(String s : sa)
			pq3.offer(s);
		for(String s : sa)
			System.out.print(pq3.poll() + " ");
	}
}
